package com.gimi.test_jpa.com.gimi.controller.login;

import cn.hutool.core.date.DateUtil;
import com.gimi.test_jpa.com.gimi.annotation.ResultInterceptor;
import com.gimi.test_jpa.com.gimi.entity.login.Account;
import com.gimi.test_jpa.com.gimi.service.login.LoginService;
import com.gimi.test_jpa.com.gimi.util.StringUtils;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 登录控制器
 * 2020-12-11
 * wqy
 */

@Controller
@Api("登录系统")
@CrossOrigin
@ResultInterceptor
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    @ApiOperation("登录接口")
    @ResponseBody
    public Map<String, Object> login(String username, String password) throws Exception {
        return loginService.login(username,password);
    }

    @PostMapping("/createAndUpdate")
    @ApiOperation("添加或修改账户信息")
    @ResponseBody
    public Map<String, Object> createAndUpdate(Account account) throws Exception {
        return loginService.createAndUpdate(account);
    }
}
